package com.hl.controller;

import com.github.pagehelper.PageHelper;
import com.hl.domain.Teacher;
import com.hl.service.TeacherService;
import com.hl.service.serviceImpl.TeacherServiceImpl;
import com.hl.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/teacher")
@RestController
public class TeacherController {
    @Autowired
    private TeacherServiceImpl teacherService;
    @GetMapping("teacherlist")
    public R AllListTeacher(int pageNum,int pageSize){
        PageHelper.startPage(pageNum,pageSize);
        List<Teacher> teachers = teacherService.AllTeacherList();
        if (teachers.size()>0){

            return R.success(teachers);
        }else {
            return R.fail("");
        }
    }
    @GetMapping("/Liketeacher")
    public R AllTeacherLike(String name){
        List<Teacher> teachers = teacherService.AllteacherLike(name);
        if (teachers.size()>0){
            return R.success(teachers);
        }else
        {
            return R.fail("");
        }
    }
    @PostMapping("/addzixuanshi")
    public R addzixuanshi(Teacher teacher){
        int i = teacherService.insertSelective(teacher);

        if (i==1){
            return R.success(teacher);

        }else {
            return R.fail("");
        }
    }
    @PostMapping("/updatezixunshi")
    R updateByPrimaryKeySelective(Teacher record){
        int i = teacherService.updateByPrimaryKeySelective(record);
        if (i==1){
            return R.success(record);
        }else
        {
            return R.fail("");
        }
    }
    @DeleteMapping("/delzixunshi")
     R delzixunshi(int id){
        int i = teacherService.deleteByPrimaryKey((long) id);
        if (i==1){
            return R.success("");
        }else {
            return R.fail("");
        }
    }


}
